Component({
  data: {
    isLoading: false,
    tabBarIndex: 0,
    isFooter: false,
  },
  options: {
    addGlobalClass: true,
  },
  properties: {
    bg: {       //背景颜色
      type: String,
      value: 'ui-BG-2'
    },
    ui: {       //其他class
      type: String,
      value: ''
    },
    img: {
      type: String,
      value: 'https://cdn.cuuo.cn/images/bg.png'
    },
    title: {
      type: String,
      value: ''
    },
    navBg: {
      type: String,
      value: 'bg-blur'
    },
    filter: {
      type: Number,
      value: 50
    },
    styles: {   //样式
      type: String,
      value: ''
    },
    loading: {
      type: Boolean,
      optionalTypes: [String],
      value: 'auto'
    },
    tabbar: {
      type: Boolean,
      value: false
    },
    footer: {
      type: Boolean,
      value: ''
    }
  },
  lifetimes: {
    created() {
      this.setLoading();
    },
    attached() {
      const loading = this.data.loading;
      this.setData({ isLoading: loading });
    },
    ready() {
      this.setTabBar();
      this.setFooterShow();
    },
  },
  observers: {
    'tabbar'() {
      this.setTabBar();
    },
    'loading'(val) {
      this.setData({ 
        isLoading: val 
      });
      this.setLoading();
    },
    'footer'() {
      this.setFooterShow();
    },
  },
  methods: {
    setTabBar() {
      let tabBar = this.data.tabbar;
      if (tabBar) {
        wx.hideTabBar();
        this._onPage();
      }
    },
    setFooterShow() {
      let footer = this.data.footer;
      let cuFooter = this.data.$cuConfig.footer;
      let isFooter = cuFooter;
      if (footer === '') {
        isFooter = cuFooter;
      } else {
        isFooter = footer;
      }
      this.setData({ isFooter: isFooter })
    },
    _onPage() {
      let page = getCurrentPages();
      if (page.length > 0) {
        let _this = this, tabBar = this.data.$cuConfig.tabBar;
        let url = page[page.length - 1].route
        tabBar.map((item, index) => {
          if (item.url === '/' + url) {
            _this.setData({ tabBarIndex: index })
          }
        })
      } else {
        this.setData({ tabBarIndex: 0 })
      }
    },
    setLoading() {
      let _this = this, loading = this.data.loading;
      setTimeout(() => {
        if (loading === 'auto') {
          _this.setData({ isLoading: false })
        }
      }, 1000);
    },
    modalSuccess() {
      return this.data.$cuStore.$Modal
    },
  },
})